// for
function findAllOccurrences(arr, target) {
    ans = []
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] == target) {
            ans.push(i)
        }
    }
    return ans
}

// forEach
function findAllOccurrences(arr, target) {
    let ans = []
    arr.forEach((val, index) => {
        val == target && ans.push(index);
    })
    return ans
}

// filter
function findAllOccurrences(arr, target) {
    var result = [];
    arr.filter(function (item, index) {
        return item === target && result.push(index);
    });
    return result;
}


// lastIndexOf+slice/splice
function findAllOccurrences(arr, target) {
    var result = [], index = arr.lastIndexOf(target);
    while (index > -1) {
        result.push(index);
        arr.splice(index, 1);//arr=arr.slice(0,index);
        index = arr.lastIndexOf(target);
    }
    return result;
}

// indexOf
function findAllOccurrences(arr, target) {
    var result = [], index = arr.indexOf(target);
    while (index > -1) {
        result.push(index);
        index = arr.indexOf(target, index + 1);
    }
    return result;
}

